package net.jxtz.jxtzos.spider.converter;


import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import lombok.extern.slf4j.Slf4j;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author lmh
 */
@Slf4j
public class ExcelPropForTime implements Converter<Long> {
    @Override
    public Class<Long> supportJavaTypeKey() {
        return Long.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    // 读调用
    @Override
    public Long convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        return null;
    }

    // 写调用
    @Override
    public CellData convertToExcelData(Long aLong, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
//        log.info("进入过滤器");
        String format = null;
        if (aLong != null && aLong.toString().length() >= 10){
            Date date = new Date(aLong * 1000);
            format = new SimpleDateFormat("yyyy-MM-dd").format(date);
//            log.info(date.toString());
//            log.info(format);
        }
        return new CellData(format);
    }
}
